package com.gavindon.android.network

import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

/**
 * description:
 * Created by liNan on  2021/5/6 16:24
 */
object RetrofitHelp {

    private const val CONNECTTIME = 3000L
    private const val WRITETIME = 3000L
    private var retrofit: Retrofit

    init {
        val logger = HttpLoggingInterceptor().apply { level = HttpLoggingInterceptor.Level.BODY }
        val client = OkHttpClient.Builder()
            .connectTimeout(CONNECTTIME, TimeUnit.MILLISECONDS)
            .writeTimeout(WRITETIME, TimeUnit.MILLISECONDS)
            .addInterceptor(logger)
            .addInterceptor(RequestInterceptor())
            .build()


        retrofit = Retrofit.Builder()
            .baseUrl("$baseUrl/")
            .client(client)
            .addConverterFactory(GsonConverterFactory.create())
            .build()
    }

    fun create(): XjdApiService {
        return retrofit.create(XjdApiService::class.java)
    }


}